/**
 *  UserTransactionManager.java        22-ott-2009
 *   
 * Copyright (c) 2009 mentalsmash.org
 *  
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 * 
 *  http://www.apache.org/licenses/LICENSE-2.0
 * 
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 * 
 *  The use of the Apache License does not indicate that this project is
 *  affiliated with the Apache Software Foundation.
 */

package org.mentalsmash.tazio.transactions;

import org.mentalsmash.tazio.transactions.management.TransactionRemotizationException;
import org.mentalsmash.tazio.transactions.management.TransactionStateException;
import org.mentalsmash.tazio.transactions.objects.TransactionalObject;

/**
 * The <tt>UserTransactionManager</tt> interface provides methods to be used
 * directly by end-users of the Transactional System, to manage their
 * transactions. <br />
 * (e.g. use it for transaction creation tasks)
 * 
 * @author Andrea Reale
 * @version 0.0.1
 */
public interface UserTransactionManager {

    /**
     * Starts the transaction associated to the thread that is invoking this
     * method.
     * <p>
     * At the end of this method call the transaction should have ended its
     * BEGINNING state and be in the RUNNING state
     * </p>
     * 
     * @return
     * @throws TransactionStateException
     * @throws TransactionRemotizationException
     */
    Transaction begin() throws TransactionStateException,
	    TransactionRemotizationException;

    /**
     * Return the transaction associated with the calling thread.
     * <p>
     * This method should never return <code>null</code>: if there's no
     * transaction associated to the thread it creates a floating transaction
     * and associates it to the thread
     * </p>
     * 
     * @return
     */
    Transaction getTransaction();

    /**
     * Starts the transaction associated to the thread that is invoking this
     * method as a Read-Only transaction. A ReadOnly transaction cannot modify
     * any {@link TransactionalObject} but it's ensured to commit.
     * <p>
     * At the end of this method call the transaction should have ended its
     * BEGINNING state and be in the RUNNING state
     * </p>
     * 
     * @return
     */
    Transaction beginReadOnly();

}
